package com.dxf.chepter05

object T62_面向对象作业 {
  def main(args: Array[String]): Unit = {

    val employee1: Employee = new NormalEmployee("小红", 100)
    val employee2: Employee = new ManagerEmployee("小明", 200, 100)

    employee1.showEmpAnnal()
    employee2.showEmpAnnal()

    employee1.testWork()
    employee2.testWork()




  }

}


//员工
abstract class Employee(inName: String, salary: BigDecimal) {
  var name: String = inName
  var salay: BigDecimal = salary

  def getAnnual()

  def showEmpAnnal(): Unit = {
    if (this.isInstanceOf[NormalEmployee]) {
      this.asInstanceOf[NormalEmployee].getAnnual()
      //普通员工
    } else if (this.isInstanceOf[ManagerEmployee]) {
      //经理
      this.asInstanceOf[ManagerEmployee].getAnnual()
    }
  }

  def testWork(): Unit = {
    if (this.isInstanceOf[NormalEmployee]) {
      this.asInstanceOf[NormalEmployee].work()
    } else if (this.isInstanceOf[ManagerEmployee]) {
      this.asInstanceOf[ManagerEmployee].manager()
    }
  }


}

//普通员工
class NormalEmployee(inName: String, salary: BigDecimal) extends Employee(inName: String, salary: BigDecimal) {


  override def getAnnual(): Unit = {
    println("普通员工工资计算=" + salary)
  }

  def work(): Unit = {
    println("普通员工work")
  }


}


class ManagerEmployee(inName: String, salary: BigDecimal, inMoneyJj: BigDecimal) extends Employee(inName: String, salary: BigDecimal) {
  //奖金
  var moneyJj: BigDecimal = inMoneyJj


  def manager(): Unit = {
    println("经理manager")
  }

  override def getAnnual(): Unit = {
    println("经理工资计算=" + (salary + moneyJj))
  }
}


